﻿using System;
using System.Data.Linq;
using System.Linq;
using WebUI.DAL;

namespace WebUI.BL.Event
{
    public class EvenShopBL
    {
        protected void clsEventShopInsert(tbl_EvenShop eventshops)
        {
            using (AdlerContextDataContext adlerContextDb = new AdlerContextDataContext())
            {
                try
                {
                    tbl_EvenShop eventshop = new tbl_EvenShop();
                    eventshop.EventNo = eventshops.EventNo;
                    eventshop.ShopNo = eventshops.ShopNo;
                    eventshop.CreatedDate = DateTime.Now;
                    eventshop.CreatedUser = eventshops.CreatedUser;
                    eventshop.Status = eventshops.Status;

                    adlerContextDb.tbl_EvenShops.InsertOnSubmit(eventshop);
                    adlerContextDb.SubmitChanges();
                }
                catch (ChangeConflictException)
                {
                    //neu xay ra loi rollback lai
                    adlerContextDb.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
                    adlerContextDb.SubmitChanges();
                }
            }
        }

        protected void clseventshopDelete(tbl_EvenShop eventshops)
        {
            using (AdlerContextDataContext adlerContextDb = new AdlerContextDataContext())
            {
                try
                {
                    var eventshop = adlerContextDb.tbl_EvenShops.Single(d => d.EventNo == eventshops.EventNo && d.ShopNo == eventshops.ShopNo);
                    eventshop.Status = eventshops.Status;

                    adlerContextDb.SubmitChanges();
                }
                catch (ChangeConflictException)
                {
                    //neu xay ra loi rollback lai
                    adlerContextDb.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
                    adlerContextDb.SubmitChanges();
                }
            }
        }
    }
}
